package com.sky.controller.admin;


import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.IDishService;
import com.sky.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜品 前端控制器
 * </p>
 *
 * @author mr.meng
 * @since 2025-10-17
 */
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Autowired
    private IDishService dishService;

    /**
     * 分页查询接口
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public Result page(DishPageQueryDTO dto){
        PageResult pageResult = dishService.pageQuery(dto);
        return Result.success(pageResult);
    }

    /**
     * 新增菜品
     * @param dto
     * @return
     */
    @PostMapping
    public Result add(@RequestBody DishDTO dto){
        dishService.add(dto);
        return Result.success();
    }

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result info(@PathVariable Long id){
        DishVO dishVO = dishService.finById(id);
        return Result.success(dishVO);
    }

    /**
     * 修改菜品接口
     * @param dto
     * @return
     */
    @PutMapping
    public Result update(@RequestBody DishDTO dto){
        dishService.update(dto);
        return Result.success();
    }

    /**
     * 删除菜品接口
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        Result result = dishService.delete(ids);
        return result;
    }
}
